package com.ruoyi.machine.advanced.repair.register.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.machine.advanced.repair.register.domain.RepairRegister;
import com.ruoyi.machine.advanced.repair.register.service.IRepairRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备维修登记表
 * 控制层
 */
@RestController
@RequestMapping("/machine/repair/register")
@Api(value = "设备维修登记模块", tags = "设备维修登记接口")
public class RepairRegisterController extends BaseController {

    @Autowired
    private IRepairRegisterService repairRegisterService;

    /**
     * 获取设备维修登记表列表
     * @param repairRegister
     * @return
     */
    @ApiOperationSupport(includeParameters = {"RepairRegister.repairRegisterId", "RepairRegister.staffRepairId", "RepairRegister.staffApplyId", "RepairRegister.repairRegisterTime"})
    @ApiOperation(value = "获取设备维修登记表列表",notes = "查询所有设备维修登记表信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody RepairRegister repairRegister) {

        startPage();

        List<RepairRegister> repairRegisterList = repairRegisterService.selectRepairRegisterList(repairRegister);

        return getDataTable(repairRegisterList);
    }

    /**
     * 导出设备维修登记表
     * @param repairRegister
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody RepairRegister repairRegister) {

        List<RepairRegister> repairRegisterList = repairRegisterService.selectRepairRegisterList(repairRegister);

        ExcelUtil<RepairRegister> util = new ExcelUtil<>(RepairRegister.class);

        return util.exportExcel(repairRegisterList, "设备维修登记表数据");
    }

    /**
     * 新增设备维修登记表
     * @param repairRegister
     * @return
     */
    @ApiOperation(value = "新增设备维修登记表", notes = "新增设备维修登记表")
    @ApiImplicitParam(name = "repairRegister", value = "新增设备维修登记表", dataType = "RepairRegister")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody RepairRegister repairRegister) {
        return toAjax(repairRegisterService.insertRepairRegister(repairRegister));
    }

    /**
     * 修改设备维修登记表
     * @param repairRegister
     * @return
     */
    @ApiOperation(value = "修改设备维修登记表", notes = "修改设备维修登记表")
    @ApiImplicitParam(name = "repairRegister", value = "修改设备维修登记表", dataType = "RepairRegister")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody RepairRegister repairRegister) {
        return toAjax(repairRegisterService.updateRepairRegister(repairRegister));
    }

    /**
     * 删除设备维修登记表
     * 仅修改删除标志位
     * @param repairRegister
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody RepairRegister repairRegister) {
        return toAjax(repairRegisterService.updateRepairRegisterDeleteFlag(repairRegister));
    }
}
